package com.cskaoyan.market.shiro;

import com.cskaoyan.market.db.domain.MarketAdmin;
import com.cskaoyan.market.db.domain.MarketUser;
import com.cskaoyan.market.service.wx.WxAuthService;
import org.apache.shiro.authc.*;
import org.apache.shiro.authz.AuthorizationInfo;
import org.apache.shiro.realm.AuthorizingRealm;
import org.apache.shiro.subject.PrincipalCollection;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;


@Component
public class WxRealm extends AuthorizingRealm {

    @Autowired
    private WxAuthService wxAuthService;

    @Override
    protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
        MarketToken usernamePasswordToken = (MarketToken) token;
        String username = usernamePasswordToken.getUsername();
        MarketUser markeduser =  wxAuthService.selectOneByUsername(username);
        return new SimpleAuthenticationInfo(markeduser,"user123" , getName());
    }


    @Override
    protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
        return null;
    }


}
